﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Target : Characters {

    protected Animator target_anim;
    protected AudioSource aud;
    public AudioClip onHit_aud;
   
	// Use this for initialization
	protected override void Start () {
        base.Start();
        target_anim = GetComponent<Animator>();
        aud = GetComponent<AudioSource>();
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    private void OnTriggerEnter2D(Collider2D collision)
    {
        float HitterX = collision.gameObject.transform.position.x;
        float myX = transform.position.x;
        if (HitterX > myX)
        {
            transform.localScale = new Vector2(-1, 1);
        }
        else
        {
            transform.localScale = new Vector2(1, 1);
        }
        target_anim.SetTrigger("OnHit");
    }

    public void PlayHitSound()
    {
        aud.PlayOneShot(onHit_aud);
    }
}
